package 集合框架;



import java.io.*;
import java.util.HashMap;
import java.util.Map;
public class WordCount {
    public static void main(String[] args) throws Exception {
        File file = new File("D:\\a.txt");
        BufferedReader br = new BufferedReader(new FileReader(file));

        Map<String, Integer> map = new HashMap<>();
        String str = null;
        StringBuilder sb = new StringBuilder();//读取文件
        while ((str = br.readLine()) !=null){
            sb.append(str);
        }
        String context =  sb.toString();
        String[] words = context.split("[ \n\t.,']");
        for (String word:
                words) {
            if (map.get(word) ==null){
                map.put(word,1);
            }else {//非第一次存储
                int oldValue = map.get(word);
                map.put(word,oldValue+1);
            }
        }
        map.forEach((k,v)-> System.out.println(k + "\t" +v));
    }
}